import { arrRoute, constantRoutes } from '@/router'
export default {
  namespaced: true,
  state: {
    routes: constantRoutes
  },
  mutations: {
    setRoute(state, data) {
      state.routes = [...constantRoutes, ...data]
    }
  },
  actions: {
    generateRoutes({ commit }, data) {
      const mark = data.map(item => item.name)
      console.log(mark)
      const userAsyncRoutes = []
      console.log(arrRoute)
      arrRoute.forEach(item => {
        if (mark.includes(item.name)) {
          userAsyncRoutes.push(item)
        }
        if ((!mark.includes(item.name)) && item.children) {
          item.children.forEach(el => {
            if (mark.includes(el.name)) userAsyncRoutes.push(el)
          })
        }
      })
      commit('setRoute', userAsyncRoutes)
      console.log(userAsyncRoutes)
      return userAsyncRoutes
    }
  }
}
